package sample2.provider.dml;

import android.content.ContentResolver;
import android.net.Uri;

/**
 * @author YUN
 */
public class SQLDeleteBuilder extends SQLBuilder {
	private SQLWhereBuilder mWhere;
	public SQLDeleteBuilder(Uri uri) {
		super(uri);
	}
	public void setWhere(SQLWhereBuilder where) {
		mWhere = where;
	}
	/**
	 * <pre>
	 * ...
	 * SQLDeleteBuilder sql = new SQLDeleteBuilder(uri);
	 * sql.addWhere("_id", "10");
	 * int delete = sql.delete(getContentResolver());
	 * ...
	 * </pre>
	 * 
	 * @param contentResolver
	 * @return Number of rows deleted
	 */
	public int delete(ContentResolver contentResolver) {
		String where = null;
		String[] selectionArgs = null;

		// WHERE ~ AND ~
		if (mWhere != null) {
			where = mWhere.getWhere();
			selectionArgs = mWhere.getSelectionArgs();
		}
		return contentResolver.delete(mUri, where, selectionArgs);
	}
}
